<!--
 * @Author: WuFeng <763467339@qq.com>
 * @Date: 2022-04-12 18:47:17
 * @LastEditTime: 2024-05-19 17:17:50
 * @LastEditors: WuFeng <763467339@qq.com>
 * @Description: 新建 / 编辑 页面
 * @FilePath: \vue-code-design\templates\vue3ElementPlus\DrawerDemo\views\{{{=it.newOptions.MODULE_VALUE}}}\components\Drawer\createStandardForm.vue
 * Copyright 版权声明
-->
<template>
  <div class="">
    <standard-form
      ref="standardForm"
      :options="options"
      v-model="formData"
    >
    </standard-form>
  </div>
</template>

<script>
import { mapGetters } from 'vuex'
import StandardForm from '@/components/StandardForm/index.vue'
import { MODULE_OPTIONS } from '../../index.js'

export default {
  name: 'Create',
  computed: {
    ...mapGetters([
      'drawerCurrent'
    ]),
    drawerType: function() {
      return this.drawerCurrent.drawerType
    }
  },
  components: {
    StandardForm
  },
  data() {
    return {
      // 组件配置参数
      options: MODULE_OPTIONS,
      // 表单数据集
      formData: {
      }
    }
  },
  watch: {
    // 表单内容体
    formData: {
      handler: function(val, oldVal) {
      },
      deep: true
    }
  },
  created() {
    // console.log(`🚀 ~ file: createStandardForm.vue ~ line 68 ~ created ~ this.drawerCurrent`, this.drawerCurrent)
    // 列表传过来的数据
    const formData = this.drawerCurrent.params.row
    this.formData = Object.assign({}, this.formData, formData)
    // *******************如果是 【编辑】 需要从接口数据的话执行一下操作
    if (this.drawerType === 'UPDATE') {
      // drawer loadding 状态 打开
      this.$store.dispatch('SetDrawerloading', true)
      setTimeout(() => {
        // drawer loadding 状态 关闭
        this.$store.dispatch('SetDrawerloading', false)
      }, 500)
    }
  },
  mounted() {

  },
  methods: {
    // 富文本编辑器内容改变
    handleEditorChange(params) {
      console.log('富文本内容改变：', params)
      const html = params.html
      this.formData.desc = html
    },
    // 重置表单
    resetChangeForm() {
    },
    // 提交表单
    submitForm() {
      return this.$refs.standardForm.submitForm().then(valid => {
        // 获取要提交的数据
        const data = this.$refs.standardForm.getFormData()
        console.log(`🚀 ~ file: createStandardForm.vue ~ line 91 ~ returnthis.$refs.standardForm.submitForm ~ data`, data)
      }).catch(err => {
        err
      })
    }
  }
}
</script>

<style rel="stylesheet/scss" lang="scss" scoped>
</style>
